<template>
<view class="page-section-spacing">
  <scroll-view scrollY="true" v-if="tableData.length" class="scroll_box" @scrolltolower="lower">
    <view class="card" v-for="(item, index) in tableData" :key="index" @tap="clikDetail(item)">
      <view class="list">
          <view class="list_item_title">
            交班时间
          </view>
          <view class="smallText">
           {{item.show_time}}
          </view>
      </view>
      <view class="list listBorder">
        <view>
          交班人
        </view>
        <view >
          管理员
        </view>
      </view>
      <view class="list">
        <view>
          实际总收入
        </view>
        <view >
          {{(Number(item.show_unionpay_total) + Number(item.cash) + Number(item.ex_cash_amount) - Number(item.recharge_fee) - Number(item.order_fee)).toFixed(2)}} 元
        </view>
      </view>
    </view>
    <AtLoadMore style="height:40px" noMoreText="没有更多了" :status="loadingStatus"/>
  </scroll-view>
</view>
</template>

<script>
import './list.scss'
import Taro from '@tarojs/taro'
import exchange from "../../api/shiftExchange.js"
import {mydateFormat } from "./../../utils/timeFormat"

export default {
  name: 'user',
  data(){
    return{
      tableData : [],
      showLoading: false, // 上滑加载更多
      loadingStatus: "loading",
      // firstIn: true, // 第一次加载数据 防止内容不足一屏高度 加载两页内容
      page: 1,
      total: 0,
      viewDetail:false,
      detailData: {
        recharge_ids: "",
      }, //详细信息
    }
  },

  mounted(){
    this.getData();
  },
  methods: {
    clikDetail(item){
      Taro.navigateTo({
        url: "/pages/shiftExchange/add"
      })
      Taro.setStorageSync('ExdetailData',JSON.stringify(item));
      console.log("shuju ", JSON.stringify(item));
    },
    close(){
      this.viewDetail = false;
    },
    // upper(e) {
    //   console.log('upper:', e)
    // },

    lower(e) { // 到底加载更多
      console.log('lower:', e)
      if(!this.showLoading){
        if(this.total != this.tableData.length){
          this.showLoading = true;
          this.loadingStatus = 'loading'
          this.getData();
        }
      }
    },

    // scroll(e) {
    //   console.log('scroll:', e)
    // },
    
    async getData(){
      let data ={
        page:this.page
      }
      let res = await exchange.changeDutyList(data);
      if(res.code == 200){
          const resdata = [...this.tableData,...res.data.result];
          this.tableData = resdata;
          this.tableData.forEach(item => {
            item.gasoli_discount = item.gasoli_order_money == '0'? '0':(Number(item.gasoli_order_money) - Number(item.gasoli_amount)).toFixed(2)
            item.diesel_discount = item.diesel_order_money == '0'? '0':(Number(item.diesel_order_money) - Number(item.diesel_amount)).toFixed(2)
            if(item.begintime == 1){
              item.nowDate = "首次收款" + " ~ " + item.endtime;
            }else{
              item.nowDate =item.begintime + " ~ " +item.endtime;
            }
            item.show_time = item.begintime + "~" + item.endtime,
            item.show_recharge_unionpay_amount = (Number(item.ex_unionpay_amount) + Number(item.ex_wechat_pay_amount)).toFixed(2);
            item.show_order_unionpay_amount = (Number(item.wechat_pay) - Number(item.ex_wechat_pay_amount) + Number(item.consume_unionpay_amount)).toFixed(2);
            item.show_unionpay_total = (Number(item.unionpay_amount) + Number(item.wechat_pay)).toFixed(2);
            item.show_all_recharge = (Number(item.oil_card_money) + Number(item.family_card_money) + Number(item.car_card_money) + Number(item.balance)).toFixed(2)
          })
          this.showLoading = false;
          this.page ++;
          this.total = res.data.total_num
          if(this.tableData.length === this.total) {
            this.loadingStatus = 'noMore'
          }else{
            this.showLoading = false;
            // if(this.firstIn){
            //   this.firstIn = false;
            //   this.lower();
            // }
          }
        }else{
          this.$message(res.msg);
        }
    }
  }
}

</script>
